import { commandRegistry } from './CommandRegistry'
import { componentRegistry } from './ComponentRegistry'
import type { CommandRegistryItem, CommandContext } from './types/core'

/**
 * 定义新命令的快捷方式
 */
export function defineCommand(item: CommandRegistryItem): CommandRegistryItem {
  // 自动注册命令
  commandRegistry.register(item)
  return item
}

/**
 * 安全获取组件实例
 */
export function safeGetComponent<T = ComponentPublicInstance>(
  context: CommandContext,
  componentId: string,
): T {
  const component = componentRegistry.getComponent<T>(componentId)
  if (!component) {
    throw new Error(`Component not found: ${componentId}`)
  }
  return component
}
